package test07.t04;

/**
 * @Author lzp
 * @Date 2024-04-11
 */
public class Test {
    /**
     * 构造学生对象 - 函数式接口作为方法参数的使用
     * @param name
     * @param age
     * @param sb
     * @return
     */
    private static Studunt build(String name,int age,StudentBuilder sb){
        return sb.create(name, age);
    }
    public static void main(String[] args) {
        // 1 匿名内部类
        Studunt stu1  = build("土豆", 20, new StudentBuilder() {
            @Override
            public Studunt create(String name, int age) {
                //调用构造方法
                return new Studunt(name,age);
            }
        });
        System.out.println(stu1);


        //2 Lambda表达式实现 - Studet create(String name,int age);
        Studunt stu2 = build("李四",10,(name,age)->new Studunt(name,age));
        System.out.println(stu2);


        //3 构造方法的引用 - 类名::new
        Studunt stu3 =build("liqibao",11,Studunt::new);
        System.out.println(stu3);
    }
}
